// pages/index.js
var urlPath = require('../../config.js');
const app = getApp();
Page({
	onShow(){
		var that = this
			
		//支付成功
		wx.request({
			url: urlPath.apiNeutralizationPaidV2, //查询
			data: {
				'openid': wx.getStorageSync('openid'),
				neutralization_id: 46,
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			},
			dataType: 'json', // 添加这个配置
			method: 'post',
			success(res) {
				if (res.data.result == "success") {
					wx.navigateTo({
						url: '/pages/payment/payment?paid_money=' +
							that.data.paid_money + "&&id=" +
							that.data.id
					});
				}
		
			}
		})
	},
	toPay() {
		var that = this
	
		wx.request({
			url: urlPath.postPayDataV2, //仅为示例，并非真实的接口地址
			data: {
				'openid': wx.getStorageSync('openid'),
				footmark_id: 114,
				
				//单纯植树动作
				// case_coding: 'CASE2103150001',//项目代码
				// cases_position_id:2,//项目位置id
				// do_type:"afforestation", //afforestation:植树 forest_management:森林管理
				// tree_items:'[{"coding":"B2104020001","amount":1}]',
				
				
				//森林管护  植树动作
				// case_coding: 'CASE202104274',//项目代码
				// cases_position_id:6,//项目位置id
				// do_type:"afforestation", //afforestation:植树 forest_management:森林管理
				// tree_items:'[{"coding":"B2104020001","amount":1}]',
				
				
				
				//森林管护  森林管护动作
				case_coding: 'CASE202104274',//项目代码
				cases_position_id:6,//项目位置id
				do_type:"forest_management", //afforestation:植树 forest_management:森林管理
				forest_management_items:'[{"id":"7","amount":1}]',
				
				
				
				paid_money: 70,
			
				
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			},
			dataType: 'json', // 添加这个配置
			method: 'post',
			success(res) {
				if (res.data.result == 'fail') {
					wx.showModal({
						title: '提示',
						content: res.data.message,

					})
				} else {
					var data = JSON.parse(res.data.data)
					wx.requestPayment({
						timeStamp: String(data.prepay_data.timeStamp),
						nonceStr: data.prepay_data.nonceStr,
						package: data.prepay_data.package,
						signType: data.prepay_data.signType,
						paySign: data.prepay_data.paySign,
						success(res) {

							//支付成功
							wx.request({
								url: urlPath.apiNeutralizationPaidV2, //查询
								data: {
									'openid': wx.getStorageSync('openid'),
									neutralization_id: data.neutralization_id,
								},
								header: {
									'content-type': 'application/x-www-form-urlencoded'
								},
								dataType: 'json', // 添加这个配置
								method: 'post',
								success(res) {
									if (res.data.result == "success") {
										wx.navigateTo({
											url: '/pages/payment/payment?paid_money=' +
												that.data.paid_money + "&&id=" +
												that.data.id
										});
									}

								}
							})
						},
						fail(res) {
							wx.showToast({
								title: '支付失败',
								icon: 'error',
								duration: 2000
							})
							console.log(res, '2222')
						}
					})
				}
			}
		})
	}

})
